package com.crm.system.controller.customerManager;

import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.entity.customerManager.*;
import com.crm.model.qo.customerManager.CustomerPoolAddQO;
import com.crm.model.qo.customerManager.CustomerPoolQO;
import com.crm.model.qo.customerManager.SendCodeQO;
import com.crm.model.vo.cluePoolManager.UserCompanyVO;
import com.crm.model.vo.customerManager.*;
import com.crm.system.service.customerManager.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 发码信息
 * @ Author ：baijian
 * @ Date   ：2021/8/7 15:21
 */
@RestController
@RequestMapping("/sendCode")
@Slf4j
public class CustomerSendCodeController {
    @Autowired
    CustomerSendCodeService customerSendCodeService;

    /**
     * 会员卡信息
     * @return
     */
    @PostMapping("/customerProductDetailMemberCardList")
    public DataResponse customerProductDetailMemberCardList(HttpServletRequest request,
                                             @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                             @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                             @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                             @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                             SendCodeQO sendCodeQO
    ){
        try{
            DhPageInfo<DetailMemberCardVO> list = customerSendCodeService.customerProductDetailMemberCardList(pageIndex,pageSize,sortName,sortOrder,sendCodeQO);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
        }catch(Exception e){
            log.error("sendCode customerProductDetailMemberCardList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 税法直通车
     * @return
     */
    @PostMapping("/customerProductDetailThroughTrainTaxList")
    public DataResponse customerProductDetailThroughTrainTaxList(HttpServletRequest request,
                                                            @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                            @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                            @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                                            @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                                            SendCodeQO sendCodeQO
    ){
        try{
            DhPageInfo<CustomerProductDetailThroughTrainTaxVO> list = customerSendCodeService.customerProductDetailThroughTrainTaxList(pageIndex,pageSize,sortName,sortOrder,sendCodeQO);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
        }catch(Exception e){
            log.error("sendCode customerProductDetailThroughTrainTaxList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 兑换码信息
     * @return
     */
    @PostMapping("/customerProductDetailExchangeCodeList")
    public DataResponse customerProductDetailExchangeCodeList(HttpServletRequest request,
                                                                 @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                                 @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                                 @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                                                 @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                                                 SendCodeQO sendCodeQO
    ){
        try{
            DhPageInfo<CustomerProductDetailExchangeCodeVO> list = customerSendCodeService.customerProductDetailExchangeCodeList(pageIndex,pageSize,sortName,sortOrder,sendCodeQO);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
        }catch(Exception e){
            log.error("sendCode customerProductDetailExchangeCodeList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 云顾问卡信息
     * @return
     */
    @PostMapping("/customerProductDetailYunList")
    public DataResponse customerProductDetailYunList(HttpServletRequest request,
                                                                 @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                                 @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                                 @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                                                 @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                                                 SendCodeQO sendCodeQO
    ){
        try{
            DhPageInfo<CustomerProductDetailYunVO> list = customerSendCodeService.customerProductDetailYunList(pageIndex,pageSize,sortName,sortOrder,sendCodeQO);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
        }catch(Exception e){
            log.error("sendCode customerProductDetailYunList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 充值卡
     * @return
     */
    @PostMapping("/customerProductDetailRechargeCodeList")
    public DataResponse customerProductDetailRechargeCodeList(HttpServletRequest request,
                                                                 @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                                 @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                                 @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                                                 @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                                                 SendCodeQO sendCodeQO
    ){
        try{
            DhPageInfo<CustomerProductDetailRechargeCodeVO> list = customerSendCodeService.customerProductDetailRechargeCodeList(pageIndex,pageSize,sortName,sortOrder,sendCodeQO);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
        }catch(Exception e){
            log.error("sendCode customerProductDetailThroughTrainTaxList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 优惠劵
     * @return
     */
    @PostMapping("/customerProductDetailCouponList")
    public DataResponse customerProductDetailCouponList(HttpServletRequest request,
                                                                 @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                                 @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                                 @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                                                 @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                                                 SendCodeQO sendCodeQO
    ){
        try{
            DhPageInfo<CustomerProductDetailCouponVO> list = customerSendCodeService.customerProductDetailCouponList(pageIndex,pageSize,sortName,sortOrder,sendCodeQO);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
        }catch(Exception e){
            log.error("sendCode customerProductDetailCouponList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }


}
